
//  ========== 
//  = Polyline = 
//  ========== 
/*
 * 创建对象         var polyline = Polyline.createNew();
 * 设置labelid        polyline.Labelid("a");
 * 创建SVG            polyline.CreateSvg();
 * 绘制                   polyline.Draw();
 * 
 * 未来：
 *      ===;
 * */
! function() {

    /**
 	 * @type ClassString
     */
    Polyline = Object.create(Object);
    Object.defineProperty(Polyline, "CreateNew", {
        value: function() {
//          return FCreateNew();

return FCreateNew();
        }

    });
	
    FCreateNew = function () {
        var polyline = Object.create(Polyline);
        //定义_labelid的属性
        var labelid_value;
        Object.defineProperty(polyline, "_labelid", {
            get: function() {
                return labelid_value;
            },
            set: function(v) {
                labelid_value = v;
            }
        });

        //定义设置_labelid属性的方法
        Object.defineProperty(polyline, "Labelid", {
            value: function(v) {
                this._labelid = v;
                return this;
            }
        });
        //定义_width的属性
        var width_value;
        Object.defineProperty(polyline, "_width", {
            get: function() {
                return width_value;
            },
            set: function(v) {
                width_value = v;
            }
        });

        //定义设置_width属性的方法
        Object.defineProperty(polyline, "Width", {
            value: function(v) {
                this._width = v;
                return this;
            }
        });
        //定义_height的属性
        var height_value;
        Object.defineProperty(polyline, "_height", {
            get: function() {
                return height_value;
            },
            set: function(v) {
                height_value = v;
            }
        });

        //定义设置_height属性的方法
        Object.defineProperty(polyline, "Height", {
            value: function(v) {
                this._height = v;
                return this;
            }
        });
        
        //定义_margins的属性
        var margins_value;
        Object.defineProperty(polyline,"_margins", {
            get: function() {
                return  margins_value;
            },
            set: function (v) {
                margins_value = v;
            }
        });
                        
        //定义设置_margins属性的方法
        Object.defineProperty(polyline, "Margins", {
            value: function(v) {
                this._margins = v ;
                return this;
                }
        });
        
        
        //定义_title_x的属性
        var title_x_value;
        Object.defineProperty(polyline   , "_title_x", {
            get: function() {
                return  title_x_value;
            },
            set: function (v) {
                title_x_value = v;
            }
        });
                        
        //定义设置_title_x属性的方法
        Object.defineProperty(polyline, "Title_x", {
            value: function(v) {
                this._title_x = v ;
                return this;
                }
        });
        
        
        //定义_title_y的属性
        var title_t_value;
        Object.defineProperty(polyline   , "_title_y", {
            get: function() {
                return  title_t_value;
            },
            set: function (v) {
                title_t_value = v;
            }
        });
                        
        //定义设置_title_y属性的方法
        Object.defineProperty(polyline, "Title_y", {
            value: function(v) {
                this._title_y = v ;
                return this;
                }
        });
        
        
        //定义_data的属性
        var data_vale;
        Object.defineProperty(polyline   , "_data", {
            get: function() {
                return  data_vale;
            },
            set: function (v) {
                data_vale = v;
            }
        });
                        
        //定义设置_data属性的方法
        Object.defineProperty(polyline, "Data", {
            value: function(v) {
                this._data = v ;
                return this;
                }
        });
        

        //定义创建svg方法
        Object.defineProperty(polyline, "CreateSvg", {
            value: function() {
                CreateSvg_polyline(this);
                return this;
            }
        });
        //定义设置Draw方法
        Object.defineProperty(polyline, "Draw", {
            value: function() {
            	Detect_function(polyline._data) ||
                draw_polyline(this);
            }
        });

        CreateSvg_polyline = function(polyline) {
                //createSvg之前先判断polyline各属性
                DetermineProperties_polyline(polyline);
                polyline.svg = d3.select("#"+polyline._labelid)
                .append("svg")
                .style("background","red")
                .attr("id", polyline._svgid)
                .attr("preserveAspectRatio", "xMidYMid meet")
                .attr("viewBox", "0 0 " + polyline._width + " " + polyline._height + " ");
//              .attr("width",polyline._width)
//              .attr("height",polyline._height);
                polyline.svg_axes_g = polyline.svg.append("g").attr("id",polyline._svg_axes_gid);
                polyline.svg_axis_x_g = polyline.svg_axes_g.append("g").attr("id",polyline._svg_axes_x_g);
                polyline.svg_axis_y_g = polyline.svg_axes_g.append("g").attr("id",polyline._svg_axes_y_g);
                
                polyline.svg_line_g = polyline.svg.append("g").attr("id",polyline._svg_lines_gid);
                
                polyline.svg_legend_g = polyline.svg.append("g").attr("id",polyline._svg_legend_gid);
                polyline.svg_legend_rect_g = polyline.svg_legend_g.append("g").attr("id",polyline._svg_legend_rects_g);
                polyline._svg_legend_texts_g = polyline.svg_legend_g.append("g").attr("id",polyline._svg_legend_texts_g);
            }
        
        draw_polyline = function (polyline) {
            
        }
            //  ========== 
            //  = 判断属性 = 
            //  ========== 
        /**
         * @param {Object} object_lh
         * @description 判断
         */
        var  Detect_function = function(object_lh) {
            return typeof(object_lh) == "undefined";
        }
        
        /** @alias shuxingzijian
         * 
         */
        DetermineProperties_polyline = function(polyline) {
        	console.log(polyline._labelid);
        	console.log($("#" + polyline._labelid));
        	console.log(d3.select("#"+polyline._labelid));
            Detect_function(polyline._labelid) ?
                alert("父容器id呢") :
                d3.select("#" + polyline._labelid)[0][0] == null ?
                alert("请检查id是否正确") :
                (SetId_polyline(polyline), 
            polyline._width = Detect_function(polyline._width) ? $("#" + polyline._labelid).width() : polyline._width,
            polyline._height = Detect_function(polyline._height) ? (polyline._width > 500) ? 500 : polyline._width : polyline._height,
            polyline._margins = Detect_function(polyline._margins) ?  {left: 150,right:150 ,top: 50,bottom: 50} : polyline._margins,
            polyline._title_x = Detect_function(polyline._title_x) ? "x轴" : polyline._title_x,
            polyline._title_y = Detect_function(polyline._title_y) ? "y轴" : polyline._title_y
                
                
                
                
                
                )
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
            
        }
        SetId_polyline = function(polyline) {
            polyline._svgid = polyline._labelid + "svg";
            polyline._svg_lines_gid = polyline._labelid +"svg_lines_g";
            polyline._svg_axes_gid = polyline._labelid + "svg_axes_g";
            polyline._svg_legend_gid = polyline._labelid + "svg_legend_g";
            
			polyline._svg_lines_line_g = polyline._labelid + "svg_lines_g"
            polyline._svg_lines_line_class = polyline._labelid + "svg_lines_line_class";
            polyline._svg_lines_node_class = polyline._labelid + "svg_lines_node_class";
            
            polyline._svg_legend_rects_g = polyline._labelid + "svg_legend_rects_g";
            polyline._svg_legend_rect_class = polyline._labelid + "svg_legend_rect_class"
            polyline._svg_legend_texts_g = polyline._labelid + "svg_legend_texts_g";
            polyline._svg_legend_text_class = polyline._labelid + "svg_legend_text_class";
            
            polyline._svg_axes_x_g = polyline._labelid + "svg_axes_x_g";
            polyline._svg_axes_y_g = polyline._labelid + "svg_axes_y_g";
            polyline._svg_axes_x_title_g = polyline._labelid + "svg_axes_x_title_g";
            polyline._svg_axes_x_axis_g = polyline._labelid + "svg_axes_x_axis_g";
            polyline._svg_axes_x_title_class = polyline._labelid + "svg_axes_x_title_class";
            polyline._svg_axes_x_axis_class = polyline._labelid + "svg_axes_x_axis_class";
            
            polyline._svg_axes_y_g = polyline._labelid + "svg_axes_y_g";
            polyline._svg_axes_y_g = polyline._labelid + "svg_axes_y_g";
            polyline._svg_axes_y_title_g = polyline._labelid + "svg_axes_y_title_g";
            polyline._svg_axes_y_axis_g = polyline._labelid + "svg_axes_y_axis_g";
            polyline._svg_axes_y_title_class = polyline._labelid + "svg_axes_y_title_class";
            polyline._svg_axes_y_axis_class = polyline._labelid + "svg_axes_y_axis_class";
        }
        Tool_polyline = function (polyline) {
            polyline.scale_linear = d3.scale.linear();
        }
        return polyline;
    };
    this.Polyline = Polyline;
}();